/**
 * Created by PyCharm.
 * User: Vladimir Kanubrikov
 * Date: 18.09.11
 * Time: 11:40
 * To change this template use File | Settings | File Templates.
 */

/**
 * Login Dialog
 */

$(function(){
   $('#logon_icon.login').click(function(){
       $('#dialog').load('/accounts/login/').dialog({
           dialogClass:'login',
           title: 'Login: ',
           modal: true,
           buttons:{
               'Login': function(){
                    var user = $('#id_username').val(),
                        pass = $('#id_password').val(),
                        csrf = $('input[name=csrfmiddlewaretoken]').val(),
                        to_page = $('#id_next').val();
                   

                   $.post('/accounts/login/',
                           {username: user,
                            password: pass,
                            next: to_page,
                            csrfmiddlewaretoken: csrf}, function(html){
                               var response = $(html).html();
                               if (response!=null){
                                $('#er').html(response);
                                $('#er').css('visibility','visible');
                               } else{
                                   $('#dialog').dialog("close");
                               }
                           },
                           'html');
               }
           }
       });
   });

});
